<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        故障模块-故障点
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrap.css">
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .layui-table-page select {
            height: 22px;
        }
    </style>
</head>

<body>
<div id="app" class="x-body">
    <div class="main_box">
        <div class="panel-heading">
            <h2>故障点</h2>
        </div>
    </div>
    <div class="page-table-body">
        <button style="float: right;" class="layui-btn" onclick="add()"><i class="layui-icon"></i>添加
        </button>
        <table class="layui-table layui-form" id="tree_table" lay-size="sm" lay-filter="tree_table"></table>

    </div>
</div>


</body>


<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../js/pub.js"></script>
<script type="text/javascript" src="../../../lib/layui/layui2.5.7.js"></script>
<script type="text/javascript" src="../../../js/vue.min.js"></script>
<script src="../../../js/x-layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    layui.use(['laydate', 'element', 'laypage', 'layer', 'form'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element;//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        var form = layui.form;
        okLoading.close($);
    });
</script>


<script>

    layui.config({
        base: '../../../js/',
    })

    var recordId = getQueryVariable("recordId");


    var vm = new Vue({
        el: "#app",
        data: {
            modelId:null
        },
        mounted() {
            this.statisticsFun();
        },
        methods: {
            statisticsFun() {
                this.modelId = recordId;
            }
        }

    });

    layui.use(['laydate', 'form', 'treeTable','table','jquery'],
        function () {
            laydate = layui.laydate;
            treeTable = layui.treeTable;
            form = layui.form;
            table = layui.table;
            o = layui.$;
            $ = layui.jquery;

          var tr = treeTable.render({
                elem: '#tree_table',
                url: $baseUrl + 'maintenance/elevatorfaultpoint/list?id='+vm.modelId,
                icon_key: 'name',
                cols: [
                      {
                          key: 'name',
                          title: '名称',
                          width: '10%',
                      },
                      {
                          key: 'type',
                          title: '类型',
                          width: '10%',
                          align: 'center',
                      },
                      {
                          key: 'remark',
                          title: '备注',
                          width: '10%',
                          align: 'center',
                      },
                      {
                          key: 'updateTime',
                          title: '更新时间',
                          width: '18%',
                          align: 'center',
                      },
                      {
                          key: 'createTime',
                          title: '增加时间',
                          width: '18%',
                          align: 'center',
                      },

                    {

                        title: '操作',
                        template:
                            function(data){
                                var html=' <a class="layui-btn layui-btn-xs" lay-filter="view">编辑</a>' +

                                    '    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-filter="del">删除</a>';
                                if(data.level<2){
                                    html+='    <a class="layui-btn layui-btn-xs" style="background: #673ab7" lay-filter="add">增加</a>' ;
                                }
                                return html;

                        },
                        fixed: 'right',
                        width: '20%'
                    }
                ],
                  done: function (res, curr, count) {
                      //是否有权限或权限是否失效
                      vm.statisticsFun();
                  }

            });
            treeTable.on('tree(add)', function (data) {
                var modelId=data.item.model.id;
                var pid=data.item.id;
                var level=data.item.level;

                if(level==0){
                    admin_add('添加', 'fault_fault_add.html?recordId=' + modelId + '&pid='+pid);
                }else  if(level==1){
                    admin_add('添加', 'fault_fault_select_add.html?recordId=' + modelId + '&pid='+pid);
                }

            });
            treeTable.on('tree(view)', function (data) {
                var data=data.item;
                var id=data.id;
                admin_add('编辑', 'fault_fault_edit.html?recordId=' + data.id);
            });
            treeTable.on('tree(del)', function (data) {
                var data=data.item;
                var id=data.id;


                layer.confirm('是否确认删除？', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    let request = {
                        url: "maintenance/elevatorfaultpoint/del/" + data.id,
                        data: {
                            userId: $userId,
                        },
                        method: "DELETE",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.msg("删除成功", {
                                icon: 1
                            });
                            t1.reload();
                        } else {
                            layer.msg("删除失败，请稍后再试！", {
                                icon: 5
                            });
                        }
                    });
                    layer.close(index);
                });
            });


        });

    function admin_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    }


    function add(){
        admin_add('添加', 'fault_fault_add.html?recordId=' + recordId + '&pid=0');
    }

</script>


</html>
